package com.logos.servlet.req;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class URLTest {

    public static void main(String[] args) throws UnsupportedEncodingException {
        String username = "张三";

        //1. URL编码
        String encode = URLEncoder.encode(username, "UTF-8");
        System.out.println("encode = " + encode);

        //2. URL解码
        String decode = java.net.URLDecoder.decode(encode, "Iso8859-1");
        System.out.println("decode = " + decode);

        // 3.转换为字节数据,编码，解码
        byte[] bytes = decode.getBytes("iso8859-1");

        // 4.将字节数组转成字符串 解码
        String s = new String(bytes, "utf-8");
        System.out.println("s = " + s);
    }
}
